package com.wnhz.work.yz.fragment.bathroomdetails;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

import com.wnhz.work.yz.R;
import com.wnhz.work.yz.activity.PlayVideoActivity;
import com.wnhz.work.yz.adapter.VideoAdapter;
import com.wnhz.work.yz.bean.VideoBean;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 * ---视频
 */
public class VideoFragment extends Fragment implements View.OnClickListener {
    private View view;
    private ListView my_listView;
    private VideoAdapter mAdapter;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_video, container, false);
        initData();

        return view;
    }

    private void initData() {

    }

    private void initView() {
        my_listView = (ListView) view.findViewById(R.id.my_listView);
        mAdapter = new VideoAdapter(getActivity(), videoBean);
        my_listView.setAdapter(mAdapter);
        my_listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent=new Intent(getContext(),PlayVideoActivity.class);
                intent.putExtra("videoUrl",videoBean.get(position).getUrl());
                intent.putExtra("img",videoBean.get(position).getImg());
                intent.putExtra("title", videoBean.get(position).getTitle());
                intent.putExtra("des", videoBean.get(position).getDescribe());
                startActivity(intent);
            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            default:
                break;
        }
    }

    List<VideoBean> videoBean = new ArrayList<>();

    public void setData(List<VideoBean> videoBean) {
        this.videoBean = videoBean;

        initView();
        // Toast.makeText(getContext(), "" + videoBean.size(), Toast.LENGTH_SHORT).show();
    }
}
